<template>
    <div>
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>商品信息</el-breadcrumb-item>
            <el-breadcrumb-item>广告管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-table
            :data="data"
            border
            style="width: 100%; margin-top: 15px;">
            <el-table-column
                prop="imgId"
                label="ID">
            </el-table-column>
            <el-table-column
                prop="categoryName"
                label="名称">
            </el-table-column>
            <el-table-column
                prop="imgUrl"
                label="图片">
                <template slot-scope="scope">
                    <img :src="scope.row.imgUrl | img" style="width:100%;height:100%;">
                </template>
            </el-table-column>
            <el-table-column
                prop="indexType"
                label="类别">
                <template slot-scope="scope">
                    {{scope.row.indexType == '1' ? '商品' : '分类'}}
                </template>
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="创建时间">
            </el-table-column>
            <el-table-column
                prop="updateTime"
                label="更新时间">
            </el-table-column>
            <el-table-column
            fixed="right"
            label="管理"
            width="100">
                <template slot-scope="scope">
                    <el-button @click="showClick(scope.row)" type="success" size="small" v-if="scope.row.status == '0'">展示</el-button>
                    <el-button @click="hiddenClick(scope.row)" type="warning" size="small" v-else-if="scope.row.status == '1'">隐藏</el-button>
                    <el-button @click="abnormalClick(scope.row)" type="info" size="small" v-else >异常</el-button>
                </template>
            </el-table-column>
            <el-table-column
            fixed="right"
            label="操作"
            width="100">
                <template slot-scope="scope">
                    <el-button @click="deleteClick(scope.row)" type="danger" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import http from '@/core/httpRequest.js'

export default {
    data(){
        return{
            data:[],
            msg:''
        }
    },
    mounted() {
        this.adverList()
    },
    methods:{
        adverList(){
            http.get('/advertising/select')
            .then(res => {
                this.data=res.data.data
            })
        },
        showClick(row){
            http.get('/advertising/show?id=' + row.imgId)
            .then(res => {
                this.msg=res.data.data
                if(this.msg > 0){
                    alert("已展示")
                }else{
                    alert("系统繁忙，请稍后再试")
                }
            })
            this.adverList()
            this.$router.go(0)
        },
        hiddenClick(row){
            http.get('/advertising/hidden?id=' + row.imgId)
            .then(res => {
                this.msg=res.data.data
                if(this.msg > 0){
                    alert("已隐藏")
                }else{
                    alert("系统繁忙，请稍后再试")
                }
            })
            this.adverList()
            this.$router.go(0)
        },
        deleteClick(row){
            if(confirm("是否确认删除？")){
                http.get('/advertising/delete?id=' + row.imgId)
                .then(res => {
                this.msg=res.data.data
                if(this.msg > 0){
                    alert("已隐藏")
                }else{
                    alert("系统繁忙，请稍后再试")
                }
            })
            this.adverList()
            this.$router.go(0)
            }
        },
        abnormalClick(row){
            row.imgId 
            alert("本条数据异常，请检查数据库内容")
        }
    }
}
</script>

<style>

</style>